package Driver;

import Model.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;


/**
 * Emulates persistence and services requests from the Event Manager
 */
public class Facade 
{
	private static Catalog catalog;
	private static BookingManager manager;
	
	/**
	 * Emulates persistence
	 */
	public static void initializeAll()
	{		
		// Initialize catalog and booking managers
		catalog = new Catalog();
		manager = new BookingManager(catalog);
		
		// Create a few venues
		Venue venueHallBuilding = new Venue("Hall building", "1455 De Maisonneuve Blvd. W., Montreal, Quebec", 30);
		Venue venueAndrewsPub = new Venue("Andrew's Pub", "1239 Guy, Montreal, QC", 20);
		
		VenueTimeslot lectureTimeslot1 = new VenueTimeslot(venueHallBuilding);
		VenueTimeslot lectureTimeslot2 = new VenueTimeslot(venueHallBuilding);		
		
		VenueTimeslot rockTimeslot1 = new VenueTimeslot(venueAndrewsPub);
		VenueTimeslot rockTimeslot2 = new VenueTimeslot(venueAndrewsPub);	
		
		EventSpecification rockShowEventSpec = new EventSpecification("Rock show", true);
		EventSpecification soen344LectureEventSpec = new EventSpecification("Soen 344 Lecture", true);
		
		Event lectureEvent1 = null;
		Event lectureEvent2 = null;
		Event rockEvent1 = null;
		Event rockEvent2 = null;
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		try 
		{
			lectureEvent1 = new Event (dateFormat.parse("2012-04-12 13:15"), 75, venueHallBuilding.getCapacity(), soen344LectureEventSpec, EventStatus.Open, lectureTimeslot1);
			lectureEvent2 = new Event (dateFormat.parse("2012-04-14 14:30"), 75, venueHallBuilding.getCapacity(), soen344LectureEventSpec, EventStatus.Open, lectureTimeslot2);
			rockEvent1 = new Event (dateFormat.parse("2012-04-14 20:15"), 75, venueAndrewsPub.getCapacity(), rockShowEventSpec, EventStatus.Open, rockTimeslot1);
			rockEvent2 = new Event (dateFormat.parse("2012-04-17 22:30"), 75, venueAndrewsPub.getCapacity(), rockShowEventSpec, EventStatus.Open, rockTimeslot2);
		} 
		catch (ParseException e)
		{
			Service.OutputManager.println("Can't parse event datetime");
			System.exit(0);
		}
		catalog.getEvents().add(lectureEvent1);
		catalog.getEvents().add(lectureEvent2);
		catalog.getEvents().add(rockEvent1);
		catalog.getEvents().add(rockEvent2);
	}

	public static Catalog getCatalog() 
	{
		return catalog;
	}

	public static void setCatalog(Catalog catalog) 
	{
		Facade.catalog = catalog;
	}

	public static BookingManager getManager() 
	{
		return manager;
	}

	public static void setManager(BookingManager manager) 
	{
		Facade.manager = manager;
	}
}
